<template>
  <ContentWrap>
      <!-- 搜索工作栏 -->
      <el-form
        class="-mb-15px"
        :model="queryParams"
        ref="queryFormRef"
        :inline="true"
        label-width="100px"
      >
      <el-form-item label="订单编号" prop="id">
          <el-input
            v-model="queryParams.id"
            placeholder="请输入订单编号"
            clearable
            class="!w-240px"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="业务" prop="operator">
          <el-input
            v-model="queryParams.operator"
            placeholder="请输入业务"
            clearable
            class="!w-240px"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="订单日期" prop="orderDateReq">
          <el-date-picker
            v-model="queryParams.orderDateReq"
            value-format="YYYY-MM-DD"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="状态" prop="status">
            <el-select
              v-model="queryParams.status"
              placeholder="订单状态"
              clearable
              class="!w-240px"
            >
              <el-option
                v-for="dict in dictType.list"
                :key="dict.id"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        <el-form-item>
          <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
          <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
        </el-form-item>
      </el-form>
    </ContentWrap>
  <!-- 列表 -->
  <ContentWrap>
      <el-table v-loading="loading" :data="list">
        <el-table-column type="index" label="序号" align="center" width="55" />
        <el-table-column label="订单编号" align="center" prop="id" />
        <el-table-column label="订单日期" align="center" prop="orderDateStr" />
        <el-table-column label="订单总数" align="center" prop="totalNum" />
        <el-table-column label="到货点" align="center" prop="arrivalPoint" />
        <el-table-column label="出货方式" align="center" prop="deliveryMode" />
        <el-table-column label="厂长" align="center" prop="manager" />
        <el-table-column label="开发业务" align="center" prop="businessName" />
        <el-table-column label="业务" align="center" prop="operator" />
        <el-table-column label="订单状态" align="center" prop="status" >
          <template #default="scope">
              <div class="flex items-center justify-center">{{ scope.row.status==='0' ? '未开始': scope.row.status==='1' ? '已完成': 
                scope.row.status==='2' ? '执行中': scope.row.status==='3' ? '部分结束': '' }}</div>
            </template>
        </el-table-column>
        <el-table-column label="备注" align="center" prop="remark" />
      </el-table>
      <!-- 分页 -->
      <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </ContentWrap>
  </template>
  
  <script lang="ts" setup>
  import * as WorkProgressReportApi from '@/api/hcxly/WorkProgressReport/Index'
  
  defineOptions({ name: 'WorkProgressReport' })
  
  const message = useMessage() // 消息弹窗
  const { t } = useI18n() // 国际化
  
  const loading = ref(true) // 列表的加载中
  const total = ref(0) // 列表的总页数
  const list = ref([]) // 列表的数据

  const queryParams = reactive({
    pageNo: 1,
    pageSize: 10,
    id: undefined,
    orderDateReq: [],
    operator : undefined,
    status : undefined
  })
  const queryFormRef = ref() // 搜索的表单
  const exportLoading = ref(false) // 导出的加载中dictType 

  const querytype = reactive({
    pageNo: 1,
    pageSize: 100,
    dictType: 'order_status'
  })
  const dictType = ref([])

  /** 查询状态 */
  const getDictType = async () => {
    dictType.value = await WorkProgressReportApi.getStatus(querytype)
    // console.log(dictType.value)
  }

  /** 查询列表 */
  const getList = async () => {
    loading.value = true
    try {
      const data = await WorkProgressReportApi.getWorkProgressReport(queryParams)
      console.log(data)
      list.value = data.list
      total.value = data.total
    } finally {
      loading.value = false
    }
  }
  
  /** 搜索按钮操作 */
  const handleQuery = () => {
    queryParams.pageNo = 1
    getList()
  }
  
  /** 重置按钮操作 */
  const resetQuery = () => {
    queryFormRef.value.resetFields()
    handleQuery()
  }

  /** 初始化 **/
  onMounted(() => {
    getList()
    getDictType()
  })
  
  </script>
